﻿#/usr/bin/python3
# -*- coding: utf-8 -*-

import threading
import time

lock = threading.Lock()
        
def change():
    # 参数为 True 阻塞，False 不阻塞
    if lock.acquire(False):
        print('get lock')
        time.sleep(1)
        print('release lock')
        lock.release()
    else:
        print('get lock fail')
    
def verify(sub):
    thread_list = []
    for i in range(10):
        t = threading.Thread(target=sub, args=())
        t.start()
        # print('thread ' + str(i) + ' start')
        thread_list.append(t)
    for j in thread_list:
        j.join()
    
if __name__ == "__main__":
    verify(change)